package org.gd.rest.jersey.server;

import com.google.gson.Gson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@Path("/metallica")
public class JSONService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @GET
    @Path("/get")
    @Produces(MediaType.TEXT_PLAIN)
    @Consumes(MediaType.TEXT_PLAIN)
    public String getTrackTxt() {
        Track track = new Track();
        track.setTitle("Enter Sandman");
        track.setSinger("Metallica");
        logger.info("[getTrackTxt]: {}", track.toString());
        return track.toString();
    }

    @GET
    @Path("/get")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public String getTrackInJSON() {
        Track track = new Track();
        track.setTitle("Enter Sandman");
        track.setSinger("Metallica");
        Gson gson = new Gson();
        logger.info("[getTrackInJSON]: {}", gson.toJson(track));
        return gson.toJson(track);
    }


    @GET
    @Path("/get")
    @Produces({MediaType.APPLICATION_XML,
            MediaType.TEXT_XML})
    @Consumes({
            MediaType.APPLICATION_XML,
            MediaType.TEXT_XML})
    public Track getTrack() {
        Track track = new Track();
        track.setTitle("Enter Sandman");
        track.setSinger("Metallica");
        logger.info("[getTrack]: {}", track.toString());
        return track;
    }
}
